import * as Router from 'koa-router';
import * as rp from 'request-promise';
import dTalkApi from '../core/dTalkApi';
import { IRouterContext } from 'koa-router';

import testService from '../services/testService';
let router = new Router();
router.prefix('/api/receData');
//加密解密传输的数据------测试
router.post('/test', async (ctx: IRouterContext, next: any) => {
    let rq: any = ctx.request
    let res = rq.body;
    console.log(res,'res_res_res_res_res_res_res_res_')
    let json=await rp.post(`http://localhost:8081/api/senddata`,{json:true});
   // console.log(json,'json_json_json_json_json_json_json_json_json_传输的数据');
    //验证签名与解密数据
    let data=await testService.encryptData(json);
    if(data){
        //console.log(data,'data_data_data_data_data_')
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=['验证未通过!!!!,主机ip错误!!!']
    }
    await next()
});

export default router


